/**
 * 
 */
define(function(require) {
	var comm = require('sdk/server');require('sdk/common');
	var globalTimeout;

	$("#ver").text(appcfg.set.version || '0.0.1');
	
	//接收推送
	var pushable = appcan.ls.val('pushable');
	$('#pushable').prop('checked',pushable==1 ?  true : false);
	$('#pushable').on('change',function(){
		if($(this).prop('checked')){
			appcan.ls.val('pushable','1');
			if(window.uexJPush){
				uexJPush.resumePush();
			}else if(window.uexXGPush){
				var userData = comm.getUser();
				//绑定别名
				uexXGPush.registerPush("user_" + userData.id);
				//tag
				uexXGPush.setTag('user');
			}
		}else{
			appcan.ls.val('pushable','0');
			if(window.uexJPush){
				uexJPush.stopPush();
			}else if(window.uexXGPush){
				uexXGPush.unregisterPush();
			}
		}
	});

	$('body').on('click','[data-action]',function(){
		var act = $(this).data('action');
		switch(act){
			case "clearCache":
				appcan.loading.show();
				//ls cache
				var lst;
            	for (lst in window.localStorage){
            		if(appcfg.set.safeStorage.indexOf(lst)===-1){
            			localStorage.removeItem(lst);
            		}
            	}
            	//sys cache
				appcan.clearOffline(function(){
					var cache = appcan.icache();
					cache.clear(function(){
						clearTimeout(globalTimeout);
						appcan.loading.hide();
						appcan.window.openToast('缓存清除成功！',1000,5);
						lst = null;
					});
				});
				globalTimeout = setTimeout(function(){
					appcan.loading.hide();
					appcan.window.openToast('操作超时！',2000,5);
					lst = null;
				},appcfg.set.outime);
				break;
			case "exit":
				comm.logout();
				break;
			case "upload":
				appcan.loading.show('检测中...',{
					mark:'puload'
				});
				comm.checkUpdate(window.platform);
				break;
		}
	});
	
	appcan.ready(function(){
		

	});
});